window.onload = function(){
    var url = '/complaint/index';
    var config = {
        elem: '#test'
        ,url:url
        ,cols: [[
            {field:'id', width:80, title: 'id', sort: true}
            ,{field:'shop_name', width:120, title: '店铺名称'}
            ,{field:'sale_type', width:86, title: '售后类型'}
            ,{field:'reason', width:130, title: '申请原因'}
            ,{field:'user_phone', width:150, title: '联系电话'}
            ,{field:'user_name', title: '联系人', width: 120}
            ,{field:'create_time', title: '投诉时间', width: 160,templet:function (item) {
                    return timestampToTime(parseInt(item.create_time));
                }}
            ,{field:'status', title: '状态', width: 100,templet:function(item){
                switch (parseInt(item.status)){
                    case 0: return '待处理';break;
                    case 1: return '处理中';break;
                    case 2: return '已完成';break;
                    case 3: return '未通过';break;
                }
                }}
            ,{fixed: 'right', minWidth:150, align:'center',title:'操作', toolbar: '#barDemo'} //这里的toolbar值是模板元素的选择器

        ]]
        ,page: true
    };
    layui.use(['form','layer','jquery','table','laydate'], function(){
        var table = layui.table,
            form = layui.form,
            layer = layui.layer;
        $ = layui.jquery;

        table.render(config);
        //监听工具条
        table.on('tool(barDemo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            switch (layEvent){
                case 'detail':
                    location.href = '/complaint/info?id='+data.id;break;
                case 'order-info':
                    location.href = '/order/get-info?id='+data.order_id;break;
            }
        });

        //搜索
        form.on("submit(serch-form)",function(data){
            var query = $("#form1").serialize();
            var url = '/complaint/index?' + query;
            config.url = url;
            table.render(config);
            return false;
        });
        //选择时间
        var laydate = layui.laydate;
        laydate.render({
            elem: '#start_time'
        });
        laydate.render({
            elem: '#end_time'
        });



    });


};
